<?php

/**

 * 同城微聚汇

 * ============================================================================

 * * 版权所有 2015-2027 武汉鼎联信息技术有限公司，并保留所有权利。

 * 网站地址: http://www.同城微聚汇.cn

 * ----------------------------------------------------------------------------

 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .

 * 不允许对程序代码以任何形式任何目的的再发布。

 * ============================================================================

 * $Author: IT宇宙人 2015-08-10 $

 *

 */ 

namespace app\home\controller; 

use think\Controller;

use think\Url;

use think\Config;

use think\Page;

use think\Verify;

use think\Db;

class Index extends Base {

    

    public function index(){      



        // 如果是手机跳转到 手机模块
        //header("Location: ".U('Admin/Admin/login'));
        if(true == isMobile()){

            header("Location: ".U('Mobile/Index/index'));

        }

        

        $hot_goods = $hot_cate = $cateList = array();

        $sql = "select a.goods_name,a.goods_id,a.shop_price,a.market_price,a.cat_id,b.parent_id_path,b.name from ".C('database.prefix')."goods as a left join ";

        $sql .= C('database.prefix')."goods_category as b on a.cat_id=b.id where a.is_hot=1 and a.is_on_sale=1 order by a.sort";//二级分类下热卖商品       

        $index_hot_goods = S('index_hot_goods');

        if(empty($index_hot_goods))

        {

            $index_hot_goods = Db::query($sql);//首页热卖商品

            S('index_hot_goods',$index_hot_goods,同城微聚汇_CACHE_TIME);

        }

       

        if($index_hot_goods){

                foreach($index_hot_goods as $val){

                        $cat_path = explode('_', $val['parent_id_path']);

                        $hot_goods[$cat_path[1]][] = $val;

                }

        }

        $hot_category = M('goods_category')->where("is_hot=1 and level=3 and is_show=1")->cache(true,同城微聚汇_CACHE_TIME)->select();//热门三级分类

        foreach ($hot_category as $v){

        	$cat_path = explode('_', $v['parent_id_path']);

        	$hot_cate[$cat_path[1]][] = $v;

        }

        

        foreach ($this->cateTrre as $k=>$v){

            if($v['is_hot']==1){

        		$v['hot_goods'] = empty($hot_goods[$k]) ? '' : $hot_goods[$k];

        		$v['hot_cate'] = empty($hot_cate[$k]) ? '' : $hot_cate[$k];

        		$cateList[] = $v;

        	}

        }

        $this->assign('cateList',$cateList);

        return $this->fetch();

    }

 

    /**

     *  公告详情页

     */

    public function notice(){

        return $this->fetch();

    }

    

    // 二维码

    public function qr_code(){        

        // 导入Vendor类库包 Library/Vendor/Zend/Server.class.php

        //http://dlshop.dliansoft.com/Home/Index/erweima/data/www.99soubao.com

         //require_once 'vendor/phpqrcode/phpqrcode.php';

         vendor('phpqrcode.phpqrcode'); 

          //import('Vendor.phpqrcode.phpqrcode');

            error_reporting(E_ERROR);            

            $url = urldecode($_GET["data"]);

            \QRcode::png($url);

			exit;        

    }

    

    // 验证码

    public function verify()

    {

        //验证码类型

        $type = I('get.type') ? I('get.type') : '';

        $fontSize = I('get.fontSize') ? I('get.fontSize') : '40';

        $length = I('get.length') ? I('get.length') : '4';

        

        $config = array(

            'fontSize' => $fontSize,

            'length' => $length,

            'useCurve' => true,

            'useNoise' => false,

        );

        $Verify = new Verify($config);

        $Verify->entry($type);        

    }

    

    // 促销活动页面

    public function promoteList()

    {

        $goodsList = DB::query("select * from __PREFIX__goods as g inner join __PREFIX__flash_sale as f on g.goods_id = f.goods_id   where ".time()." > start_time  and ".time()." < end_time");

        $brandList = M('brand')->getField("id,name,logo");

        $this->assign('brandList',$brandList);

        $this->assign('goodsList',$goodsList);

        return $this->fetch();

    }

    

    function truncate_tables (){

        $tables = DB::query("show tables");

        $table = array('tp_admin','tp_config','tp_region','tp_system_module','tp_admin_role','tp_system_menu','tp_article_cat','tp_wx_user');

        foreach($tables as $key => $val)

        {                                    

            if(!in_array($val['Tables_in_同城微聚汇'], $table))                             

                echo "truncate table ".$val['Tables_in_同城微聚汇'].' ; ';

                echo "<br/>";         

        }                

    }



    /**

     * 猜你喜欢

     * @author lxl

     * @time 17-2-15

     */

    public function ajax_favorite(){

        $p = I('p/d',1);

        $i = I('i',5); //显示条数

        $favourite_goods = M('goods')->where("is_recommend=1 and is_on_sale=1")->order('goods_id DESC')->page($p,$i)->cache(true,同城微聚汇_CACHE_TIME)->select();//首页推荐商品

        $this->assign('favourite_goods',$favourite_goods);

        return $this->fetch();

    }

}